 import {getUserInfo, login} from '../../api/user';
 import {setToken} from '../../utils/Auth'
 import {Loading} from "../../utils/Loading";
 import {Toast} from '../../utils/Toast';
/**
 * @Description: userAction
 * @author TangYong
 * @date 2022/5/4
 */
export const Set_Token = (token) => {
    return {
        type: 'Set_Token',
        token
    }
}
 // export const Set_User = (user) => {
 //     return {
 //         type: 'Set_User',
 //         user
 //     }
 // }
export const LoginAction=(userInfo)=>{
    const {mobile,password}=userInfo;
    return dispatch => {
        Loading.show();
        login({ mobile: mobile.trim(), password: password }).then(response => {
            Loading.hidden();
            //console.log("token----------------",response)
            //const { data } = response
            //本地存储token
            setToken(response)
            //全局状态
            const action = Set_Token(response.token)
            dispatch(action);
        }).catch(error => {
            Loading.hidden();
            Toast.showWarning(error.toString())
            //console.log(error,"response")
            //reject(error)
        }).finally(()=>{
            Loading.hidden();
        })
    }
}

// export const getUser=()=>{
//      return dispatch => {
//          Loading.show();
//          getUserInfo().then(response => {
//              let {user}=response
//              Loading.hidden();
//              console.log("user----------------",response)
//              //const { data } = response
//              //全局状态
//              const action = Set_User(user)
//              dispatch(action);
//          }).catch(error => {
//              Loading.hidden();
//          }).finally(()=>{
//              Loading.hidden();
//          })
//      }
//  }




